package com.ziyun.erp.modules.goodsCategoryScholarship.service.impl;

import com.utility.New;
import io.renren.common.utils.R;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.goodsCategoryScholarship.dao.GoodsCategoryScholarshipDao;
import com.ziyun.erp.modules.goodsCategoryScholarship.entity.GoodsCategoryScholarshipEntity;
import com.ziyun.erp.modules.goodsCategoryScholarship.service.GoodsCategoryScholarshipService;


@Service("goodsCategoryScholarshipService")
public class GoodsCategoryScholarshipServiceImpl extends ServiceImpl<GoodsCategoryScholarshipDao, GoodsCategoryScholarshipEntity> implements GoodsCategoryScholarshipService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<GoodsCategoryScholarshipEntity> page = this.selectPage(
                new Query<GoodsCategoryScholarshipEntity>(params).getPage(),
                new EntityWrapper<GoodsCategoryScholarshipEntity>()
                .eq("deleted",0)
        );

        return new PageUtils(page);
    }

    @Override
    public void flagDel(String ids) {
        this.baseMapper.flagDel(ids);
    }

    @Override
    public Page<GoodsCategoryScholarshipEntity> queryNewPage(Page<GoodsCategoryScholarshipEntity> page, Map<String, Object> params) {
        page.setRecords(this.baseMapper.queryNewPage(page,params));
        return page;
    }

    @Override
    public R getScholarShipByCatId(Integer catId) {
        Map<String, Object> map = New.hashMap();
        map.put("category_id",catId);
        map.put("deleted",0);
        List<GoodsCategoryScholarshipEntity> goodsCategoryScholarshipEntities = this.baseMapper.selectByMap(map);
        if(goodsCategoryScholarshipEntities != null && goodsCategoryScholarshipEntities.size() == 1){
            return R.ok().put("mark",false);
        }else if(goodsCategoryScholarshipEntities.size() == 0){
            return R.ok().put("mark",true);
        }
        return R.error("错误数据,该分类下找到多个返回值");
    }


}
